#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>
#include "gestion_personnel.h" 
#include "callbacks.h"
#include "interface.h"
#include "support.h"
#include <stdlib.h>
#include <string.h>



gboolean
on_label2_activate_link                (GtkLabel        *label,
                                        gchar           *arg1,
                                       gpointer         user_data)
{ 
 
  return FALSE;
}


gboolean
on_label5_activate_link                (GtkLabel        *label,
                                        gchar           *arg1,
                                        gpointer         user_data)
{

  return FALSE;
}


gboolean
on_label6_activate_link                (GtkLabel        *label,
                                        gchar           *arg1,
                                        gpointer         user_data)
{

  return FALSE;
}


gboolean
on_label3_activate_link                (GtkLabel        *label,
                                        gchar           *arg1,
                                        gpointer         user_data)
{

  return FALSE;
}


gboolean
on_label4_activate_link                (GtkLabel        *label,
                                        gchar           *arg1,
                                        gpointer         user_data)
{

  return FALSE;
}


void on_button1_clicked (GtkWidget *objet_graphique, gpointer user_data) //button1=bouton valider dans fenetre ajout personnel
{ personnel P;
  int erreur=0;
  FILE *f;
	GtkWidget *entry1;
	GtkWidget *entry2;
	GtkWidget *entry3;
	GtkWidget *entry4;
	GtkWidget *entry5;
	GtkWidget *entry6;
	GtkWidget *entry7;
	GtkWidget *entry8;
	
	GtkWidget *window2;
	GtkWidget *window22;
	GtkWidget *window33;

	GtkWidget *label57; //Id
	GtkWidget *label58; //Age
	GtkWidget *label59; //Fonction
	GtkWidget *label60; //Mot de passe
	GtkWidget *label61; //Nom
	GtkWidget *label62; //Prenom
	GtkWidget *label63; //Nationalité
	GtkWidget *label64; //CIN
	
	char Buf1[50]="  ";
	char Buf2[50]="  ";
	char Buf3[50]="  ";
	char Buf4[50]="  ";
	char Buf5[50]="  ";
	char Buf6[50]="  ";
	char Buf7[50]="  ";
	char Buf8[50]="  ";



	entry1 = lookup_widget(objet_graphique, "entry1");
	entry2 = lookup_widget(objet_graphique, "entry2");
	entry3 = lookup_widget(objet_graphique, "entry3");
	entry4 = lookup_widget(objet_graphique, "entry4");
	entry5 = lookup_widget(objet_graphique, "entry5");
	entry6 = lookup_widget(objet_graphique, "entry6");
	entry7 = lookup_widget(objet_graphique, "entry7");
	entry8 = lookup_widget(objet_graphique, "entry8");

	label57 = lookup_widget(objet_graphique, "label57");
	label58 = lookup_widget(objet_graphique, "label58");
	label59 = lookup_widget(objet_graphique, "label59");
	label60 = lookup_widget(objet_graphique, "label60");
	label61 = lookup_widget(objet_graphique, "label61");
	label62 = lookup_widget(objet_graphique, "label62");
	label63 = lookup_widget(objet_graphique, "label63");
	label64 = lookup_widget(objet_graphique, "label64");
	

	P.id = atoi(gtk_entry_get_text(GTK_ENTRY(entry1)));
	strcpy(P.nom, gtk_entry_get_text(GTK_ENTRY(entry2)));
	strcpy(P.prenom, gtk_entry_get_text(GTK_ENTRY(entry3)));
	strcpy(P.nat, gtk_entry_get_text(GTK_ENTRY(entry4)));
	P.cin = atoi(gtk_entry_get_text(GTK_ENTRY(entry5)));
	P.age = atoi(gtk_entry_get_text(GTK_ENTRY(entry6)));
	strcpy(P.fonction, gtk_entry_get_text(GTK_ENTRY(entry7)));
	strcpy(P.mp, gtk_entry_get_text(GTK_ENTRY(entry8)));

	
	
	
	
	
if (existe(P.id,"personnel.txt")==1 ) 
	{ sprintf(Buf1,"Identifiant déja existant");  
	  gtk_label_set_text(GTK_LABEL(label57),Buf1);   
	  erreur=1;
	}
else{sprintf(Buf1,"           ");  gtk_label_set_text(GTK_LABEL(label57),Buf1);};


if (strlen(gtk_entry_get_text(GTK_ENTRY(entry1)))<4 ) 
	{sprintf(Buf1,"Identifiant trop court");  
	gtk_label_set_text(GTK_LABEL(label57),Buf1); 
	erreur=1;
	}
else{sprintf(Buf1,"            ");  gtk_label_set_text(GTK_LABEL(label57),Buf1);};


if (P.age<18 || P.age>99 ) 
	{sprintf(Buf2,"Age incorrect"); 
	gtk_label_set_text(GTK_LABEL(label58),Buf2); 
	erreur=1;
	}
else{sprintf(Buf2,"             ");  gtk_label_set_text(GTK_LABEL(label58),Buf2);};


if (strcmp(P.fonction,"medecin")!=0 && strcmp(P.fonction,"infirmier")!=0 && strcmp(P.fonction,"administrateur")!=0 ) 
	{sprintf(Buf3,"Fonction incorrecte"); 
	gtk_label_set_text(GTK_LABEL(label59),Buf3); 
	erreur=1;
	}
else{sprintf(Buf3,"              ");  gtk_label_set_text(GTK_LABEL(label59),Buf3);};


if (strlen(P.mp)<4 ) 
	{sprintf(Buf4,"Mot de passe trop court");  
	gtk_label_set_text(GTK_LABEL(label60),Buf4); 
	erreur=1;
	}
else{sprintf(Buf4,"               ");  gtk_label_set_text(GTK_LABEL(label60),Buf4);};


if (strlen(P.nom)<4 ) 
	{sprintf(Buf5,"Nom trop court");  
	gtk_label_set_text(GTK_LABEL(label61),Buf5); 
	erreur=1;
	}
else{sprintf(Buf5,"               ");  gtk_label_set_text(GTK_LABEL(label61),Buf5);};


if (strlen(P.prenom)<4 ) 
	{sprintf(Buf6,"Prenom trop court");  
	gtk_label_set_text(GTK_LABEL(label62),Buf6); 
	erreur=1;
	}
else{sprintf(Buf6,"               ");  gtk_label_set_text(GTK_LABEL(label62),Buf6);};


if (strlen(P.nat)<4 ) 
	{sprintf(Buf7,"Nationalité incorrecte");  
	gtk_label_set_text(GTK_LABEL(label63),Buf7); 
	erreur=1;
	}
else{sprintf(Buf7,"               ");  gtk_label_set_text(GTK_LABEL(label63),Buf7);};

if (strlen(gtk_entry_get_text(GTK_ENTRY(entry5)))<6 ) 
	{sprintf(Buf8,"CIN incorrect");  
	gtk_label_set_text(GTK_LABEL(label64),Buf8); 
	erreur=1;
	}
else{sprintf(Buf8,"               ");  gtk_label_set_text(GTK_LABEL(label64),Buf8);}




	    if (erreur==0 )	
		{ajouter_personnel(&P);
		window22 = create_window22(); //window22=fenetre de succés d'ajout
		gtk_widget_show (window22);
	        window2 = lookup_widget(objet_graphique, "window2"); //window2=fenere d'ajout de personnel
 		gtk_widget_destroy(window2);
     		}
	
     	
	
	
	

}
void on_button2_clicked (GtkWidget *objet_graphique, gpointer user_data)
{ GtkWidget *window111;
  GtkWidget *window2;
           window2 = lookup_widget(objet_graphique, "window2");//window2=fenere d'ajout de personnel
 	   gtk_widget_destroy(window2);

	   window111 = create_window111(); //window111=Menu gestion personnel 
	   gtk_widget_show (window111);
}








void on_button4_clicked (GtkWidget *objet_graphique, gpointer user_data)//button4=bouton valider dans la fenetre suppression
{int iden;

	GtkWidget *entry10;
	GtkWidget *window5;
	GtkWidget *window8;
	GtkWidget *window4;

	GtkWidget *label66;

	char Buf[50]="  ";
	label66 = lookup_widget(objet_graphique, "label66");

	entry10 = lookup_widget(objet_graphique, "entry10");//entry10=champ id du personnel à supprimer
	iden= atoi(gtk_entry_get_text(GTK_ENTRY(entry10)));
	if (existe(iden,"personnel.txt")!=0)
		{supprimer_personnel(iden);
	         window4 = lookup_widget(objet_graphique, "window4"); //window4=fenere dde suppression de personnel
 		 gtk_widget_destroy(window4);
		window5 = create_window5(); //window5=fenetre de succés de supression
		gtk_widget_show (window5);
		}
	else { sprintf(Buf,"Identifiant non existant"); 
	       gtk_label_set_text(GTK_LABEL(label66),Buf);
	     }


 	
	
}


void on_button3_clicked (GtkWidget *objet_graphique, gpointer user_data) //button3=bouton de choix modifications
{ GtkWidget *window6;
  GtkWidget *window3;
  GtkWidget *entry9;
  GtkWidget *entry13;
  GtkWidget *label96;
  GtkWidget *radiobutton1;
  GtkWidget *radiobutton2;
  GtkWidget *radiobutton3;
  GtkWidget *radiobutton4;
  GtkWidget *radiobutton5;
  GtkWidget *radiobutton6;
  GtkWidget *radiobutton7;
  GtkWidget *radiobutton8;


	int iden;
	char Buf[50]=" ";
	char newentry[20];

  FILE *f;
  FILE *g;
  char nom[20],pren[20],nat[20],fonction[20],mp[20];
  char nnom[20],npren[20],nnat[20],nfonction[20],nmp[20];
  long int cin,ncin;
  int age,id,nage,nid;  
  int i=0;

 GtkWidget *label116;//label 116=modification enregistrée
 char Buf2[]="                                       ";


	
	
entry9 = lookup_widget(objet_graphique, "entry9");//entry9=ID du personnel à modifier
iden = atoi(gtk_entry_get_text(GTK_ENTRY(entry9)));

entry13 = lookup_widget(objet_graphique, "entry13"); //entry13=Nouveau champ







if (existe(iden,"personnel.txt")==0) {label96 = lookup_widget(objet_graphique, "label96");
				    sprintf(Buf,"Identifiant non existant"); 
				    gtk_label_set_text(GTK_LABEL(label96),Buf);
				    }
else {   label96 = lookup_widget(objet_graphique, "label96");//label 96=identifiant non existant
         sprintf(Buf," "); 
         gtk_label_set_text(GTK_LABEL(label96),Buf);


	
	 radiobutton1 = lookup_widget(objet_graphique, "radiobutton1");
	 radiobutton2 = lookup_widget(objet_graphique, "radiobutton2");
	 radiobutton3 = lookup_widget(objet_graphique, "radiobutton3");
	 radiobutton4 = lookup_widget(objet_graphique, "radiobutton4");
	 radiobutton5 = lookup_widget(objet_graphique, "radiobutton5");
	 radiobutton6 = lookup_widget(objet_graphique, "radiobutton6");
	 radiobutton7 = lookup_widget(objet_graphique, "radiobutton7");
	 radiobutton8 = lookup_widget(objet_graphique, "radiobutton8");
	 f=fopen("personnel.txt","r");
	 g=fopen("new.txt","w");
	     
	  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radiobutton1))==TRUE)
          {  while (i<nombre_personnel("personnel.txt") )
    			{
     				fscanf(f, "%d %s %s %s %ld %d %s %s",&id,nom,pren,nat,&cin,&age,fonction,mp);
     				if (id==iden)
	  			{nid=atoi(gtk_entry_get_text(GTK_ENTRY(entry13))); 
				 fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",nid,nom,pren,nat,cin,age,fonction,mp);	
				} 
     				else fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,age,fonction,mp);
				i++;
	
    			}
		label116 = lookup_widget(objet_graphique, "label116"); //label 116=modification enregistrée
       		sprintf(Buf2,"Nouvel identifiant enregistré"); 
       		gtk_label_set_text(GTK_LABEL(label116),Buf2);
	}
         if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radiobutton2))==TRUE)
          {  while (i<nombre_personnel("personnel.txt") )
    			{
     				fscanf(f, "%d %s %s %s %ld %d %s %s",&id,nom,pren,nat,&cin,&age,fonction,mp);
     				if (id==iden)
	  			{strcpy(nnom,gtk_entry_get_text(GTK_ENTRY(entry13))); 
				 fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nnom,pren,nat,cin,age,fonction,mp);	
				} 
     				else fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,age,fonction,mp);
				i++;
	
    			}
		label116 = lookup_widget(objet_graphique, "label116"); //label 116=modification enregistrée
       		sprintf(Buf2,"Nouveau nom enregistré"); 
       		gtk_label_set_text(GTK_LABEL(label116),Buf2);
	}
	  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radiobutton3))==TRUE)
          {  while (i<nombre_personnel("personnel.txt") )
    			{
     				fscanf(f, "%d %s %s %s %ld %d %s %s",&id,nom,pren,nat,&cin,&age,fonction,mp);
     				if (id==iden)
	  			{strcpy(npren,gtk_entry_get_text(GTK_ENTRY(entry13))); 
				 fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,npren,nat,cin,age,fonction,mp);	
				} 
     				else fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,age,fonction,mp);
				i++;
	
    			}
		label116 = lookup_widget(objet_graphique, "label116"); //label 116=modification enregistrée
       		sprintf(Buf2,"Nouveau prenom enregistré"); 
       		gtk_label_set_text(GTK_LABEL(label116),Buf2);
	}
	  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radiobutton5))==TRUE)
          {  while (i<nombre_personnel("personnel.txt") )
    			{
     				fscanf(f, "%d %s %s %s %ld %d %s %s",&id,nom,pren,nat,&cin,&age,fonction,mp);
     				if (id==iden)
	  			{ 
				 fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,gtk_entry_get_text(GTK_ENTRY(entry13)),cin,age,fonction,mp);	
				} 
     				else fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,age,fonction,mp);
				i++;
	
    			}
		label116 = lookup_widget(objet_graphique, "label116"); //label 116=modification enregistrée
       		sprintf(Buf2,"Nouvelle nationalité enregistrée"); 
       		gtk_label_set_text(GTK_LABEL(label116),Buf2);
	}
	  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radiobutton6))==TRUE)
          {  while (i<nombre_personnel("personnel.txt") )
    			{
     				fscanf(f, "%d %s %s %s %ld %d %s %s",&id,nom,pren,nat,&cin,&age,fonction,mp);
     				if (id==iden)
	  			{ncin=atoi(gtk_entry_get_text(GTK_ENTRY(entry13))); 
				 fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,ncin,age,fonction,mp);	
				} 
     				else fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,age,fonction,mp);
				i++;
	
    			}
		label116 = lookup_widget(objet_graphique, "label116"); //label 116=modification enregistrée
       		sprintf(Buf2,"Nouveau CIN/Passeport enregistré"); 
       		gtk_label_set_text(GTK_LABEL(label116),Buf2);
	}
	  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radiobutton4))==TRUE)
          {  while (i<nombre_personnel("personnel.txt") )
    			{
     				fscanf(f, "%d %s %s %s %ld %d %s %s",&id,nom,pren,nat,&cin,&age,fonction,mp);
     				if (id==iden)
	  			{nage=atoi(gtk_entry_get_text(GTK_ENTRY(entry13))); 
				 fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,nage,fonction,mp);	
				} 
     				else fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,age,fonction,mp);
				i++;
	
    			}
		label116 = lookup_widget(objet_graphique, "label116"); //label 116=modification enregistrée
       		sprintf(Buf2,"Nouvel age enregistré"); 
       		gtk_label_set_text(GTK_LABEL(label116),Buf2);
	}
	  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radiobutton7))==TRUE)
          {  while (i<nombre_personnel("personnel.txt") )
    			{
     				fscanf(f, "%d %s %s %s %ld %d %s %s",&id,nom,pren,nat,&cin,&age,fonction,mp);
     				if (id==iden)
	  			{strcpy(nfonction,gtk_entry_get_text(GTK_ENTRY(entry13)));
				 fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,age,nfonction,mp);	
				} 
     				else fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,age,fonction,mp);
				i++;
	
    			}
		label116 = lookup_widget(objet_graphique, "label116"); //label 116=modification enregistrée
       		sprintf(Buf2,"Nouvelle fonction enregistrée"); 
       		gtk_label_set_text(GTK_LABEL(label116),Buf2);
	}
	  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radiobutton8))==TRUE)
          {  while (i<nombre_personnel("personnel.txt") )
    			{
     				fscanf(f, "%d %s %s %s %ld %d %s %s",&id,nom,pren,nat,&cin,&age,fonction,mp);
     				if (id==iden)
	  			{strcpy(nmp,gtk_entry_get_text(GTK_ENTRY(entry13))); 
				 fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,age,fonction,nmp);	
				} 
     				else fprintf(g, "%d\t%s\t%s\t%s\t%ld\t%d\t%s\t%s\n",id,nom,pren,nat,cin,age,fonction,mp);
				i++;
	
    			}
		label116 = lookup_widget(objet_graphique, "label116"); //label 116=modification enregistrée
       		sprintf(Buf2,"Nouveau mot de passe enregistré"); 
       		gtk_label_set_text(GTK_LABEL(label116),Buf2);
	}


       
 



fclose(f);
fclose(g);  
remove("personnel.txt");
rename("new.txt","personnel.txt");
}

}



void on_mod_clicked (GtkWidget *objet_graphique, gpointer user_data) //mod=bouton de modification dans le menu gestion personnel
{ GtkWidget *window3;
 GtkWidget *window111;

 window3 = create_window3();//window3=fenere modification personnel
 gtk_widget_show (window3);
 window111 = lookup_widget(objet_graphique, "window111");
 gtk_widget_destroy(window111);
}


void on_ver_clicked (GtkWidget *objet_graphique, gpointer user_data) //ver=bouton de verification dans le menu gestion personnel 
{  
 GtkWidget *window112;
  window112 = create_window112(); //window4=fenetre de suppression personnel
  gtk_widget_show (window112);
}


void on_sup_clicked(GtkWidget *objet_graphique, gpointer user_data)
{ GtkWidget *window4;
  window4 = create_window4(); //window4=fenetre de suppression personnel
 gtk_widget_show (window4);

}


void on_aff_enter (GtkWidget *objet_graphique, gpointer user_data)
{ GtkWidget *window113;
  window113 = create_window113(); //window113=fenetre d'affichage d'un personnel
 gtk_widget_show (window113);

}


void on_aff2_clicked (GtkWidget *objet_graphique, gpointer user_data)
{ GtkWidget *window114;

window114 = create_window114(); //window114=fenetre d'affichage de tout le personnel
 gtk_widget_show (window114);
  

}


void on_button16_clicked (GtkWidget *objet_graphique , gpointer user_data)//button16=bouton d'ajout dans le menu gestion personnel 

{ GtkWidget *window2; //window2=fenere d'ajout de personnel
  GtkWidget *window111; //window111=fenere du menu gestion personnel


 window2 = create_window2();
 gtk_widget_show (window2);
 window111 = lookup_widget(objet_graphique, "window111");
 gtk_widget_destroy(window111);
  

}










void on_button25_clicked (GtkWidget  *objet_graphique, gpointer user_data)
{ GtkWidget *window111;
  GtkWidget *window22;


window111 = create_window111();//window111=fenere du menu gestion personnel
 gtk_widget_show (window111);
window22 = lookup_widget(objet_graphique, "window22");//window2=fenere succés d'ajout de personnel
 gtk_widget_destroy(window22);

}


void on_button26_clicked  (GtkWidget  *objet_graphique, gpointer user_data)
{ GtkWidget *window22;

 
 window22 = lookup_widget(objet_graphique, "window22");//window2=fenere d'ajout de personnel
 gtk_widget_destroy(window22);

}


void on_button31_clicked (GtkWidget *objet_graphique, gpointer user_data)
{ 
  GtkWidget *window111;
  GtkWidget *window5;

 /*window111 = create_window111();//window111=fenere du menu gestion personnel
 gtk_widget_show (window111);*/
 window5 = lookup_widget(objet_graphique, "window5");//window5=fenere de suppression de personnel
 gtk_widget_destroy(window5);

}






void on_button33_clicked (GtkWidget *objet_graphique,gpointer user_data)

{ int id;
  GtkWidget *label70;
  GtkWidget *entry11;

entry11 = lookup_widget(objet_graphique, "entry11"); id = atoi(gtk_entry_get_text(GTK_ENTRY(entry11)));
label70 = lookup_widget(objet_graphique, "label70");
char Buf[100]="           ";
if(existe(id,"personnel.txt")!=0)
	{sprintf(Buf,"Personnel existant dans la base de données de la clinique"); 
	gtk_label_set_text(GTK_LABEL(label70),Buf);
	}
else { sprintf(Buf,"Personnel non existant dans la base de données de la clinique"); 
       gtk_label_set_text(GTK_LABEL(label70),Buf);
     }
   
}












void on_button34_clicked  (GtkWidget *objet_graphique,gpointer user_data)
{ GtkWidget *window111;
 window111 = lookup_widget(objet_graphique, "window111");//window111=fenere menu gestion personnel
 gtk_widget_destroy(window111);
}


void on_button35_clicked (GtkWidget *objet_graphique,gpointer user_data)
{FILE *f;
 int id,iden,age,i=0;
 char nom[20],prenom[20],fonction[20],mp[20],nat[20];
 long int cin;
 int v=0;
char Buf[50]="               ";

char Buf0[50]="               ";
char Buf1[50]="               ";
char Buf2[50]="               ";
char Buf3[50]="               ";
char Buf4[50]="               ";
char Buf5[50]="               ";
char Buf6[50]="               ";
char Buf7[50]="               ";
char Buff[50]="               ";
char Buf99[50]="               ";


 GtkWidget *label91; //id non existant(erroné) 
 GtkWidget *entry12;//id entry
//infos à afficher:
 GtkWidget *label75;
 GtkWidget *label77;
 GtkWidget *label79;
 GtkWidget *label81;
 GtkWidget *label83;
 GtkWidget *label85;
 GtkWidget *label87;
 GtkWidget *label89;

 


 entry12 = lookup_widget(objet_graphique, "entry12"); iden = atoi(gtk_entry_get_text(GTK_ENTRY(entry12)));
 

if(existe(iden,"personnel.txt")==0)  
	{
	label91 = lookup_widget(objet_graphique, "label91");	
	sprintf(Buf,"Cet identifiant n'appartient à aucun personnel");  
	gtk_label_set_text(GTK_LABEL(label91),Buf);
	
	
	}
else { label91 = lookup_widget(objet_graphique, "label91");
       sprintf(Buf99," ");  
       gtk_label_set_text(GTK_LABEL(label91),Buf99);
	

	f=fopen("personnel.txt","r");
	while(i < nombre_personnel("personnel.txt") && v==0)
  		{fscanf(f,"%d %s %s %s %ld %d %s %s",&id,nom,prenom,nat,&cin,&age,fonction,mp); 
		if (id==iden)   
	       { 
		 
		 label75 = lookup_widget(objet_graphique, "label75");
		 label77 = lookup_widget(objet_graphique, "label77");
		 label79 = lookup_widget(objet_graphique, "label79");
		 label81 = lookup_widget(objet_graphique, "label81");
		 label83 = lookup_widget(objet_graphique, "label83");
		 label85 = lookup_widget(objet_graphique, "label85");
		 label87 = lookup_widget(objet_graphique, "label87");
		 label89 = lookup_widget(objet_graphique, "label89");

		sprintf(Buf0,"%d",id);
		sprintf(Buf1,"%s",nom); 
		sprintf(Buf2,"%s",prenom); 
		sprintf(Buf3,"%s",nat); 
		sprintf(Buf4,"%ld",cin); 
		sprintf(Buf5,"%d",age); 
		sprintf(Buf6,"%s",fonction); 
		sprintf(Buf7,"%s",mp);  

		gtk_label_set_text(GTK_LABEL(label75),Buf0);
		gtk_label_set_text(GTK_LABEL(label77),Buf1);
		gtk_label_set_text(GTK_LABEL(label79),Buf2);
		gtk_label_set_text(GTK_LABEL(label81),Buf3);
		gtk_label_set_text(GTK_LABEL(label83),Buf4);
		gtk_label_set_text(GTK_LABEL(label85),Buf5);
		gtk_label_set_text(GTK_LABEL(label87),Buf6);
		gtk_label_set_text(GTK_LABEL(label89),Buf7);
		v=1;
	      }
    		i++;
  		}
     }
 
  
}

	




















void on_button36_clicked (GtkWidget  *objet_graphique, gpointer user_data)
{ GtkWidget *window111;
  GtkWidget *window3;


window111 = create_window111();//window111=fenere du menu gestion personnel
 gtk_widget_show (window111);
window3 = lookup_widget(objet_graphique, "window3");//window3=fenere modification personnel
 gtk_widget_destroy(window3);

}


void on_radiobutton4_pressed (GtkWidget *objet_graphique,gpointer user_data)
{ 

}


void on_radiobutton8_pressed  (GtkWidget *objet_graphique,gpointer user_data)
{ 

}


void on_radiobutton7_pressed  (GtkWidget *objet_graphique,gpointer user_data)
{ 

}


void on_radiobutton3_pressed (GtkWidget *objet_graphique,gpointer user_data)
{ 

}


void on_radiobutton2_pressed  (GtkWidget *objet_graphique,gpointer user_data)
{ 

}


void on_radiobutton6_pressed (GtkWidget *objet_graphique,gpointer user_data)
{ 

}


void on_radiobutton5_pressed  (GtkWidget *objet_graphique,gpointer user_data)
{ 

}




void on_radiobutton1_pressed(GtkWidget *objet_graphique,gpointer user_data)
{
 
}


void on_button37_clicked (GtkWidget *objet_graphique, gpointer user_data) //Bouton affichage personnel suivant
{
GtkWidget *label99;
  GtkWidget *label101;
  GtkWidget *label103;
  GtkWidget *label105;
  GtkWidget *label107;
  GtkWidget *label109;
  GtkWidget *label111;
  GtkWidget *label113;

char nom[20],pren[20],nat[20],fonction[20],mp[20],sid[10];
long int cin;
int age,id;

int i=0;
int b=0;
int e=0;

char Buff0[]="                ";
char Buff1[]="                ";
char Buff2[]="                ";
char Buff3[]="                ";
char Buff4[]="                ";
char Buff5[]="                ";
char Buff6[]="                ";
char Buff7[]="                ";

FILE *f;
f=fopen("personnel.txt","r");


  

    

 while(i<nombre_personnel("personnel.txt") && b==0)
{

  fscanf(f,"%d %s %s %s %ld %d %s %s",&id,nom,pren,nat,&cin,&age,fonction,mp);
 sprintf(sid, "%d", id);
 label99 = lookup_widget(objet_graphique, "label99");
 if(strcmp(sid,gtk_label_get_text(label99))==0) e=1;
 if(strcmp(sid,gtk_label_get_text(label99))!=0 && e==1)
{
 label99 = lookup_widget(objet_graphique, "label99");
 sprintf(Buff0,"%d",id); 
 gtk_label_set_text(GTK_LABEL(label99),Buff0);

 label101 = lookup_widget(objet_graphique, "label101");
 sprintf(Buff1,"%s",nom); 
 gtk_label_set_text(GTK_LABEL(label101),Buff1);

 label103 = lookup_widget(objet_graphique, "label103");
 sprintf(Buff2,"%s",pren); 
 gtk_label_set_text(GTK_LABEL(label103),Buff2);

 label105 = lookup_widget(objet_graphique, "label105");
 sprintf(Buff3,"%s",nat); 
 gtk_label_set_text(GTK_LABEL(label105),Buff3);

 label107 = lookup_widget(objet_graphique, "label107");
 sprintf(Buff4,"%ld",cin); 
 gtk_label_set_text(GTK_LABEL(label107),Buff4);

 label109 = lookup_widget(objet_graphique, "label109");
 sprintf(Buff5,"%d",age); 
 gtk_label_set_text(GTK_LABEL(label109),Buff5);

 label111 = lookup_widget(objet_graphique, "label111");
 sprintf(Buff6,"%s",fonction); 
 gtk_label_set_text(GTK_LABEL(label111),Buff6);

 label113 = lookup_widget(objet_graphique, "label113");
 sprintf(Buff7,"%s",mp); 
 gtk_label_set_text(GTK_LABEL(label113),Buff7);
 b=1;
}
i++;

}

}




void
on_button38_clicked  (GtkWidget *objet_graphique, gpointer user_data) //Bouton commencer affichage personnels
{GtkWidget *label99;
  GtkWidget *label101;
  GtkWidget *label103;
  GtkWidget *label105;
  GtkWidget *label107;
  GtkWidget *label109;
  GtkWidget *label111;
  GtkWidget *label113;

char nom[20],pren[20],nat[20],fonction[20],mp[20];
long int cin;
int age,id;

char Buff0[]="                ";
char Buff1[]="                ";
char Buff2[]="                ";
char Buff3[]="                ";
char Buff4[]="                ";
char Buff5[]="                ";
char Buff6[]="                ";
char Buff7[]="                ";



  FILE *f;
  f=fopen("personnel.txt","r");
 
   

 

  fscanf(f,"%d %s %s %s %ld %d %s %s",&id,nom,pren,nat,&cin,&age,fonction,mp);

 label99 = lookup_widget(objet_graphique, "label99");
 sprintf(Buff0,"%d",id); 
 gtk_label_set_text(GTK_LABEL(label99),Buff0);

 label101 = lookup_widget(objet_graphique, "label101");
 sprintf(Buff1,"%s",nom); 
 gtk_label_set_text(GTK_LABEL(label101),Buff1);

 label103 = lookup_widget(objet_graphique, "label103");
 sprintf(Buff2,"%s",pren); 
 gtk_label_set_text(GTK_LABEL(label103),Buff2);

 label105 = lookup_widget(objet_graphique, "label105");
 sprintf(Buff3,"%s",nat); 
 gtk_label_set_text(GTK_LABEL(label105),Buff3);

 label107 = lookup_widget(objet_graphique, "label107");
 sprintf(Buff4,"%ld",cin); 
 gtk_label_set_text(GTK_LABEL(label107),Buff4);

 label109 = lookup_widget(objet_graphique, "label109");
 sprintf(Buff5,"%d",age); 
 gtk_label_set_text(GTK_LABEL(label109),Buff5);

 label111 = lookup_widget(objet_graphique, "label111");
 sprintf(Buff6,"%s",fonction); 
 gtk_label_set_text(GTK_LABEL(label111),Buff6);

 label113 = lookup_widget(objet_graphique, "label113");
 sprintf(Buff7,"%s",mp); 
 gtk_label_set_text(GTK_LABEL(label113),Buff7);



 

}

